package com.gewu.bluetoothflow.view;

import android.animation.ObjectAnimator;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.gewu.bluetoothflow.R;

import java.util.ArrayList;


public class LoadingDialog extends Dialog {
    private String TAG = LoadingDialog.class.getName();


    ArrayList<String> roomName = new ArrayList<String>();
    TextView tipName = null;
    TextView tipContent = null;
    ImageView loading = null;
    Spinner raddr = null;


    String mtitle = "";
    String mContent = "";
    Context mcontext = null;

    public LoadingDialog(@NonNull Context context, int themeResId, String title, String content) { // roomList:MutableList<RoomInfo>
        super(context, themeResId);
        mcontext = context;
        this.mtitle = title;
        mContent = content;
    }
   public interface EditDevClickListener{
        public void onclickSave();
    }

    public EditDevClickListener listener;

    public void setSaveListener(EditDevClickListener listener){
          this.listener = listener;
    }

    public LoadingDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        mcontext = context;
    }
    ObjectAnimator objectAnimator;
    Animation animator ;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_loading);
        tipName = findViewById(R.id.tipName);
        loading = findViewById(R.id.iv_loading);
        animator = AnimationUtils.loadAnimation(mcontext,R.anim.rotate);
       // LinearInterpolator lin = new LinearInterpolator();
        animator.setInterpolator(new LinearInterpolator());

        if (mtitle.length() > 0) {
            tipName.setText(mtitle);
        }
        if (animator != null){
            loading.startAnimation(animator);
            //loadingView.visibility = View.VISIBLE;
        }
//        objectAnimator = ObjectAnimator.ofFloat(loading,"rotation",360f);
//        objectAnimator.setDuration(1000);
//        objectAnimator.setRepeatCount(Animation.INFINITE);
//        objectAnimator.start();
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (animator != null){
            loading.clearAnimation();
        }
//        if (objectAnimator != null){
//            objectAnimator.cancel();
//            objectAnimator = null;
//        }
    }
}
